package com.ybkj.o2o.zhuanxian.manager.impl;

import com.ybkj.o2o.zhuanxian.entity.Payrecordorder;
import com.ybkj.o2o.zhuanxian.manager.PayRecordOrderManager;
import com.ybkj.o2o.zhuanxian.service.PayRecordOrderService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class DefaultPayRecordOrderManager implements PayRecordOrderManager {

  @Autowired
  private PayRecordOrderService payRecordOrderService;

  @Override
  @Transactional(rollbackFor = Exception.class)
  public Payrecordorder insert(Long orderId, Double money, String payRecordTypeOrder) {
    Payrecordorder payRecordOrder = new Payrecordorder();
    payRecordOrder.setCreated(new Date());
    payRecordOrder.setUpdated(new Date());
    payRecordOrder.setOrderId(orderId);
    payRecordOrder.setMoney(money);
    payRecordOrder.setPayRecordTypeOrder(payRecordTypeOrder);
    payRecordOrder.setTreatment(false);

    payRecordOrderService.insert(payRecordOrder);

    return payRecordOrder;
  }

  @Override
  public Payrecordorder findByIdAndAppKey(Long id) {
    return payRecordOrderService.findById(id);
  }

  @Override
  public Payrecordorder update(Long id) {
    Payrecordorder order = payRecordOrderService.findById(id);
    order.setTreatment(true);
    int update = payRecordOrderService.update(order);
    return order;
  }

}
